﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using System.Collections.ObjectModel;


namespace NobleTech.Products.CreatureKingdom.WPFClient.Controls
{
    public class HasSelectedIndexConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            if ((value as int?) == null) return false;
            if ((value as int?) == -1) return false;
            return true;            
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }


    public class MultiplyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            if ((value as double?) == null) return 0;
            double param;
            if (Parameter as string == null) return 0;
            if (!(double.TryParse(Parameter.ToString(), out param))) return 0;
            return (value as double?) * (param);
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }


    public class RoundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            double? DoubleToConvert = value as double?;
            if (DoubleToConvert != null)
                return Math.Round((double)DoubleToConvert,2);
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }

    public class BoolToIntConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            bool? BoolToConvert = value as bool?;
            if (BoolToConvert != null)
                return ((bool)BoolToConvert) ? 1 : 0;
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }

    public class NegativeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            double? Number = value as double?;
            if (Number != null)
                return -(double)Number;
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }

    public class DivideByMinusTwoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            double? Number = value as double?;
            if (Number != null)
                return ((double)Number) / -2;
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }

    public class DivideByTwoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            double? Number = value as double?;
            if (Number != null)
                return ((double)Number) / 2;
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }


    public class MinusRadToDegreeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            double? Number = value as double?;
            if (Number != null)
                return ((double)Number) * -180 / Math.PI;
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }

    public class IsAliveToOpacityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            bool? IsAlive = value as bool?;
            if (IsAlive != null)
                return (bool)IsAlive ? 1 : 0.4;
            return 1;
        }

        public object ConvertBack(object value, Type targetType, object Parameter, CultureInfo Culture)
        {
            throw (new Exception("Not implemented"));
        }
    }
}
